package com.baweiwei.userapi.dao;


import com.baweiwei.common.entity.Users;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.math.BigDecimal;

public interface UserDao extends JpaRepository<Users,Integer>, JpaSpecificationExecutor<Users> {


    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "update bw_users set u_money=u_money-?2 where u_id=?1 and u_money-?2>=0",nativeQuery = true)
    int updateMoney(Integer userId, BigDecimal money);

}
